'''
Created on Apr 23, 2012
TC ID: Ecom_5026
Desc: Kiem thu chuc nang thiet lap khoa hoc cho nhom nguoi dung
@author: lavang
'''
import unittest
from HTMLTestRunner import HTMLTestRunner
import time
from Functions.globalFunc import readData, preCondition, endCondition
from Functions.userGroupsFunc import fc_set, clickOnTabGroupCourse, ClickOnGroup,\
    clickOnUserGroups, setGroupCourse, isGroupCourseSet
from Functions.loginPageFunc import login
from Functions.logoutFunc import logout

username=readData("username")
password=readData("password")
tm_userGroupName=readData("groupName",index=3)
tm_user=readData("users",index=3)
tm_set=fc_set
tm_course=readData("courseName",index=3)
class Ecom_5026(unittest.TestCase):


    def setUp(self):
        preCondition(self)

    def test_Ecom_5026(self):
        print "Buoc 1: Dang nhap vao website"
        login(self,username,password)
        
        print "Buoc 2: Click vao User groups"
        clickOnUserGroups(self)
        
        print "Buoc 3: Click vao group muon thiet lap khoa hoc"
        ClickOnGroup(self,tm_userGroupName)
        
        print "Buoc 4: Click vao tab Group course"
        clickOnTabGroupCourse(self)
       
        print "Buoc 5: Thiet lap khoa hoc cho chom"
        setGroupCourse(self,tm_course,set='on')
        
        print "Buoc 6: Dang xuat tai khoan va dang nhap lai"
        logout(self)
        login(self,username,password)
        
        print "Buoc 7: Click vao User group"
        clickOnUserGroups(self)
        
        print "Buoc 8: click vao group vua thiet lap khoa hoc"
        ClickOnGroup(self,tm_userGroupName)
        
        print "Buoc 9: Click vao tab Group courses"
        clickOnTabGroupCourse(self)
     
        print "Buoc 10: Kiem tra khoa hoc vua duoc thiet lap"
        self.assertTrue(isGroupCourseSet(self,tm_course), "Failed!")
        print "Passed! Thiet lap khoa hoc thanh cong"
        
    def tearDown(self):
        endCondition(self)
       
if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5026)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang thiet lap khoa hoc nhom nguoi dung'
                    )
    runner.run(suite)